﻿using System;
using System.Configuration;
using Crap4Net;
using Crap4Net.CoverageParsers;
using Crap4Net.CCParsers;

namespace Crap4Net_Console
{
    class Program
    {

        static void Main(string[] args)
        {

            try
            {
                var CoverageTool = ConfigurationManager.AppSettings["CoverageTool"];
                var CCTool = ConfigurationManager.AppSettings["CCTool"];
                var coverageFile = ConfigurationManager.AppSettings["CoverageReport"];
                var ccFile = ConfigurationManager.AppSettings["CCReport"];
                var outputFile = ConfigurationManager.AppSettings["OutputFile"];
                var formatterName = ConfigurationManager.AppSettings["FormatterType"];


                //create parsers
                CrapAnalyzer.CCParser = CCParserFactory.CreateParser(CCTool);
                CrapAnalyzer.CoverageParser = CoverageParserFactory.CreateParser(CoverageTool);


                //create the report
                var Results = CrapAnalyzer.CreateCrapReport(coverageFile, ccFile);

                //write the result to the disk
                IFormatter formatter = FormatterFactory.GetFormatter(formatterName);
                formatter.FormatAndSaveToFile(Results, outputFile);
            }
            catch (Exception exception)
            {
                Console.WriteLine(string.Format("An exception occured whilst creating the CRAP report.  Details:\n{0}", exception));
            }
            

        }

    }
}
